<?php

namespace app\admin\model;

use app\common\model\BaseModel;

class AuthGroup extends BaseModel
{
    // 开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';
    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = 'updatetime';
    public function setPidAttr($value)
    {
        if(!empty($value)){
            if(is_array($value)){
                $value = $value[count($value)-1];
            }
        }
        return $value;
    }
    public function getNameAttr($value, $data)
    {
        return __($value);
    }
    protected function getPid($id)
    {
        $pid = $this->where('id',$id)->value('pid');
        if($pid>0){
            $tempid = $this->getPid($pid);
        }
        $pids = [$id];
        if(!empty($tempid)){
            $pids = array_merge($pids,$tempid);
        }
        return $pids;
    }
    public function getRulesAttr($value)
    {
        if(!empty($value)){
            if(is_string($value)){
                $value = explode(',',$value);
                foreach ($value as $k=>$v){
                    if($v!='*'){
                        $value[$k] = intval($v);
                    }

                }
            }
        }else{
            $value = [];
        }
        return $value;
    }
    public function setRulesAttr($value)
    {
        if(!empty($value)){
            if(is_array($value)){
                $value = implode(',',$value);
            }
        }
        return $value;
    }

}
